package com.xr.wage.classItem;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.xr.common.CommUtil;

/**
 * checkClassViewModel
 */
public class checkClassViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  Dataset ds=getDataset("datasetCheckClass");
	  DBStatement dbs=new DBStatement(); 
	  
      CommUtil.dbsUpdateData(dbs, ds, "WA_CHECK_CLASS", "CHECK_CLASS_ID","SEQ_WA");
      dbs.close();
    //super.doUpdateData(parameters, outParameters);
  }
  public void CheckClassDel(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement(); 
	  Dataset ds=getDataset("datasetCheckClass");
	  dbs.setSql("delete from wa_check_hritems where CHECK_CLASS_ID="+ds.getString("CHECK_CLASS_ID"));
	  dbs.execute();
	  dbs.setSql("delete from WA_CHECK_CLASS where CHECK_CLASS_ID="+ds.getString("CHECK_CLASS_ID"));
	  dbs.execute();
	  dbs.close(); 
  }
  
  public void CheckItemAdd(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement(); 
	  Dataset dsC=getDataset("datasetCheckClass");
	  Dataset ds=getDataset("datasetClassItem");
	  dbs.setSql("select count(1) from wa_check_hritems where CHECK_CLASS_ID="+dsC.getString("CHECK_CLASS_ID")+" and hritems_id="+ds.getString("hritems_id"));
	  if(dbs.query().getInt(0)==0){
		  dbs.setSql("insert into wa_check_hritems(waclass_id, classitem_id, check_class_id, name, hritems_id, visible_order)" +
		  		"values("+ds.getString("waclass_id")+","+ds.getString("classitem_id")+","+dsC.getString("check_class_id")+",'"+ds.getString("name")+"',"+ds.getString("hritems_id")+","+ds.getString("visible_order")+")");
		  dbs.execute();
	  }
	  dbs.close();
  }
  public void CheckItemDel(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement();
	  Dataset dsC=getDataset("datasetCheckClass");
	  Dataset ds=getDataset("datasetCheckItem");
	  dbs.setSql("delete from wa_check_hritems where CHECK_CLASS_ID="+dsC.getString("CHECK_CLASS_ID")+" and hritems_id="+ds.getString("HRITEMS_ID"));
	  dbs.execute();
	  dbs.close();
  }
  public void setFieldHritems_order(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement();
	  Dataset ds=getDataset("datasetFieldHritems");
	 
	  CommUtil.dbsUpdateData(dbs, ds, "WA_FIELD_HRITEMS", "WA_FIELD_HRITEMS_ID");
 
	  dbs.close();
  }
  public void setFieldHritems_add(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement();
	  Dataset dsf=getDataset("datasetField");
	  Dataset ds=getDataset("datasetClassItem");
	  dbs.setSql("insert into wa_field_hritems(WA_FIELD_HRITEMS_ID,WA_FIELD_ID,hritems_id) select seq_wa.nextval,"+dsf.getString("WA_FIELD_ID")+","+ds.getString("HRITEMS_ID")+" from dual where not exists(select 1 from wa_field_hritems where WA_FIELD_ID="+dsf.getString("WA_FIELD_ID")+" and HRITEMS_ID="+ds.getString("HRITEMS_ID")+" )");
	  dbs.execute();
	  dbs.close();
  }
  public void setFieldHritems_del(ParameterSet parameters, ParameterSet outParameters)
  throws Exception {
	  DBStatement dbs=new DBStatement();
	  Dataset ds=getDataset("datasetFieldHritems");
	  dbs.setSql("delete from wa_field_hritems where WA_FIELD_HRITEMS_ID="+ds.getString("WA_FIELD_HRITEMS_ID"));
	  dbs.execute();
	  dbs.close();
  }
}
